var http = require('http');
var request = require('request');
http.createServer(function (request, response) {
    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // 发送响应数据 "Hello World"
    response.end('Hello World...\n');    
}).listen(8082);
console.log('Server running at http://127.0.0.1:8082/');
//PUT /api/Form/b713476c-738b-4058-865f-d85ac73f49ac?diseaseId=15 HTTP/1.1
var h = {
    Host: 'www.cnrds.net',
    Connection: 'keep-alive',
    "Content-Length": 4798,
    Accept: '*/*',
    Origin: 'http://www.cnrds.net',
    "X-Requested-With": 'XMLHttpRequest',
    "User-Agent": 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
    "Content-Type": 'application/json',
    Referer: 'http://www.cnrds.net/Pages/EditForm/15/b713476c-738b-4058-865f-d85ac73f49ac',
    "Accept-Encoding": 'gzip, deflate',
    "Accept-Language": 'zh-CN,zh;q=0.9',
    Cookie: 'ASP.NET_SessionId=211cijocmaoghjinqaabrr1w; .AspNet.ApplicationCookie=3Qm3bqqjU_GwIMuNoIOmvBnmfl_F2J9oFTfoAzmy3Yh_7juQhqPysY6DlrzuF5QGwbcKwAyFzWbOZmGGONmZi_PHmGyeZObpRGEX7DU_7IqDq9BOCA4egNR6fxM2XseBdz73UoBy3ImWotsbnvHKMYvuHYR3ZbpphfzIGJlaCNrj0KAQICV2jaNDC5tu1fwxkpQMmqEHjyw7VfyIWBB6UK2p4Y3vr6yK1rGW5imU1qKYZMxjRF4RsJrvapzZw_4y9ZSGu5EgIp2FtGQjM3cqVftAwWHujzL0ibBsHzWtaIJ6GazwK4mMmqEUlhDvkwm6t6K4tXIQi7a7sfig-TygcQfEUfwXPvWNGIY4RWclkOnK9cv2YGkEYaSkkELzk3fnRXHU_EhgbD2Ym4R5bTsGyEPa_TvNGK12hPJLA9RIbxNMXeCG4-x5Fkp-F1vdZGoADAqdFQ8ctUMPHmCh5i3YRsekz8vtUEzVFtGtYdz1iSY'
};
var cookie = 'JSESSIONID=E2E6555A4E2BD5D07A8566EA66EF4BC7;userid=11621';
var HOST = 'https://www.yunjingzhi.com';
var PORT = '';
var method = 'post';
var bodydata = {param:'',bc:1,bq:'',order:0,pbrq:'2019-05-29'};
var callBackFunction = function(){};
var path = '/yunjingservice/txform/getmtxformuserlist.shtml';
nodePostGetRequest(HOST, PORT, method, bodydata, callBackFunction, path, cookie)

function nodePostGetRequest(HOST, PORT, method, bodydata, callBackFunction, path, cookie) {
    //把将要发送的body转换为json格式 
    var body = bodydata;
    var bodyString = JSON.stringify(body);
    //http 头部
    var headers = {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Content-Length': bodyString.length,
        'Cookie': cookie
    };

    //用与发送的参数类型
    var options = {
        host: HOST, //ip
        port: 443, //port
        path: path, //get方式使用的地址
        method: method, //get方式或post方式
        headers: headers,
        proxy: "http://127.0.0.1:8888"
    };
    var req = http.request(options, function (res) {
        res.setEncoding('utf-8');

        var responseString = '';

        res.on('data', function (data) {
            responseString += data;
        });

        res.on('end', function () {
            //这里接收的参数是字符串形式,需要格式化成json格式使用
            var resultObject = JSON.parse(responseString);
            console.log('-----resBody-----', resultObject);
            callBackFunction(responseString);
        });

        req.on('error', function (e) {
            // TODO: handle error.
            console.log('-----error-------', e);
        });
    });
    req.write(bodyString);
    req.end();
}